package com.ml.doctor.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ml.doctor.R;
import com.ml.doctor.bean.QianYueBean;
import com.ml.doctor.bean.XXBean;
import com.ml.doctor.network.NetworkApi;
import com.ml.doctor.network.NetworkManager;
import com.ml.doctor.utils.ToastUtil;
import com.ml.doctor.view.CycleImageView;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class QianYueActivity extends BaseActivity {

    @BindView(R.id.iv_avatar)
    CycleImageView ivAvatar;
    @BindView(R.id.txt_name)
    TextView txtName;
    @BindView(R.id.txt_sex)
    TextView txtSex;
    @BindView(R.id.txt_age)
    TextView txtAge;
    @BindView(R.id.txt_phone)
    TextView txtPhone;
    @BindView(R.id.txt_bs)
    TextView txtBs;
    @BindView(R.id.txt_xx)
    TextView txtXx;
    QianYueBean qianYueBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qian_yue);
        ButterKnife.bind(this);
        setTopTitle("签约");
        initData();
        setupView();
    }

    private void initData() {
        qianYueBean = getSerializableParam("qianyue", QianYueBean.class);
    }

    private void setupView() {
        String xx = "";
        Glide.with(this).load(qianYueBean.user_photo).asBitmap().into(ivAvatar);
        txtName.setText(qianYueBean.bname);
        txtSex.setText(qianYueBean.sex);
        txtAge.setText(qianYueBean.age + "岁");
        txtPhone.setText("联系方式：" + qianYueBean.tel);
        if (!TextUtils.isEmpty(qianYueBean.eating_habits)) {
            xx += XXBean.eat[Integer.parseInt(qianYueBean.eating_habits) - 1];
        }
        if (!TextUtils.isEmpty(qianYueBean.smoke)) {
            xx += "," + XXBean.smoke[Integer.parseInt(qianYueBean.smoke) - 1];
        }
        if (!TextUtils.isEmpty(qianYueBean.drink)) {
            xx += "," + XXBean.drink[Integer.parseInt(qianYueBean.drink) - 1];
        }
        if (!TextUtils.isEmpty(qianYueBean.exercise_habits)) {
            xx += "," + XXBean.sport[Integer.parseInt(qianYueBean.exercise_habits) - 1];
        }
        txtXx.setText(xx);
        if (!TextUtils.isEmpty(qianYueBean.mh) && !qianYueBean.mh.equals("尚未填写")) {
            String arr[] = qianYueBean.mh.split(",");
            String mh = "";
//            for (int i = 0; i < arr.length; i++) {
//
//                mh += BsBean.BS[Integer.parseInt(arr[i]) - 1] + ",";
//            }
//            if (!TextUtils.isEmpty(mh)) {
//                mh = mh.substring(0, mh.length() - 1);
//            }
            txtBs.setText("病        史：" + qianYueBean.mh);
        } else {
            txtBs.setText("病        史：尚未填写");
        }
    }

    @OnClick({R.id.txt_jj, R.id.txt_js})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.txt_jj:
                commit(2);
                break;
            case R.id.txt_js:
                commit(1);
                break;
        }
    }

    public void commit(int state) {
        Map<String, String> map = new HashMap<>();
        map.put("bid", qianYueBean.bid + "");
        map.put("state", state + "");
        NetworkManager.getInstance().getResultClass(NetworkApi.BasicUrl + "docter/docter_agree_shenqing", map, String.class, new NetworkManager.SuccessCallback<String>() {
            @Override
            public void onSuccess(String response) {
                ToastUtil.showShort(QianYueActivity.this, "成功");
                setResult(RESULT_OK);
                finish();
            }
        }, new NetworkManager.FailedCallback() {
            @Override
            public void onFailed(String message) {
                ToastUtil.showShort(QianYueActivity.this, message);
            }
        });
    }

}
